package com.graduation.springbootinit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.graduation.springbootinit.model.entity.ShopPart.OrderItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderItemMapper extends BaseMapper<OrderItem> {
    
    /**
     * 获取指定商铺在指定年月的所有订单项
     */
    @Select("SELECT oi.* FROM shop_part_order_items oi " +
            "JOIN shop_part_orders o ON oi.order_id = o.id " +
            "WHERE oi.store_id = #{storeId} " +
            "AND YEAR(o.finish_time) = #{year} " +
            "AND LPAD(MONTH(o.finish_time), 2, '0') = LPAD(#{month}, 2, '0') " +
            "AND o.status = 3")
    List<OrderItem> getMonthlyOrderItems(@Param("storeId") Long storeId,
                                       @Param("year") Integer year,
                                       @Param("month") Integer month);
}